// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: ProCompareAction.java

package com.market.web.action;

import java.util.ArrayList;

import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.market.bean.Product;
import com.market.web.utils.ListUtils;

// Referenced classes of package com.market.web.action:
// BaseAction

public class ProCompareAction extends BaseAction2
{

    public ProCompareAction()
    {
    }

    public String execute() throws Exception
    {
        String sId[] = getRequest().getParameterValues("id");
        if (sId == null || sId.length <= 1)
        {
            ActionMessages error = new ActionMessages();
            error.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(
                    "\u8BF7\u9009\u62E9\u4E00\u4E2A\u4EE5\u4E0A\u7684\u5546\u54C1!", false));
            //saveErrors(request, error);
            return INPUT;//mapping.getInputForward();
        }
        long id[] = new long[sId.length];
        int length = sId.length <= 4 ? id.length : 4;
        for (int i = 0; i < length; i++)
            try
            {
                id[i] = Long.parseLong(sId[i]);
            }
            catch (Exception exception)
            {
                logger.error("",exception);
            }

        Product pro = getProductService().findById(id[0]);
        return processCompare(pro.getCategory(), id);
    }

    private String processCompare(String category, long id[])
    {
        ArrayList list;
        if ("beer".equals(category))
        {
            list = new ArrayList();
            for (int i = 0; i < id.length; i++)
            {
                Product pro = getProductService().findById(com.market.bean.Ball.class, id[i]);
                if (pro != null)
                    list.add(pro);
            }

            getRequest().setAttribute("productList", ListUtils.convert(list, com.market.bean.Ball.class,
                    com.market.web.form.BallForm.class));
            return "beercompare";//mapping.findForward("beercompare");
        }
        if ("rice".equals(category))
        {
            list = new ArrayList();
            for (int i = 0; i < id.length; i++)
            {
                Product pro = getProductService().findById(com.market.bean.Bowb.class, id[i]);
                if (pro != null)
                    list.add(pro);
            }

            getRequest().setAttribute("productList", ListUtils.convert(list, com.market.bean.Bowb.class,
                    com.market.web.form.BowbForm.class));
            return "ricecompare";//mapping.findForward("ricecompare");
        }
       /* if ("arrow".equals(category))
        {
            list = new ArrayList();
            for (int i = 0; i < id.length; i++)
            {
                Product pro = getProductService().findById(com.market.bean.Arrow.class, id[i]);
                if (pro != null)
                    list.add(pro);
            }

            request.setAttribute("productList", ListUtils.convert(list, com.market.bean.Arrow.class,
                    com.market.web.form.ArrowForm.class));
            return mapping.findForward("arrowcompare");
        }
        if ("collimator".equals(category))
        {
            list = new ArrayList();
            for (int i = 0; i < id.length; i++)
            {
                Product pro = getProductService().findById(com.market.bean.Collimator.class, id[i]);
                if (pro != null)
                    list.add(pro);
            }

            request.setAttribute("productList", ListUtils.convert(list, com.market.bean.Collimator.class,
                    com.market.web.form.CollForm.class));
            return mapping.findForward("collcompare");
        }*/
        if ("safety".equals(category))
        {
            list = new ArrayList();
            for (int i = 0; i < id.length; i++)
            {
                Product pro = getProductService().findById(com.market.bean.Safety.class, id[i]);
                if (pro != null)
                    list.add(pro);
            }

            getRequest().setAttribute("productList", ListUtils.convert(list, com.market.bean.Safety.class,
                    com.market.web.form.SafetyForm.class));
            return "safetycompare";//mapping.findForward("safetycompare");
        }
        list = new ArrayList();
        for (int i = 0; i < id.length; i++)
        {
            Product pro = getProductService().findById(com.market.bean.Bowa.class, id[i]);
            if (pro != null)
                list.add(pro);
        }

        getRequest().setAttribute("productList", ListUtils.convert(list, com.market.bean.Bowa.class,
                com.market.web.form.BowaForm.class));
        return "safetycompare";//mapping.findForward("bowacompare");
    }
}
